﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TanWeb.Models.Entities.Infrastructure;
using TanWeb.Helpers;

namespace TanWeb.Models.Entities
{
    [Table("Product")]
    public class Product : Entity
    {
        [Column("GroupId", Order = 1)]
        public int GroupId { set; get; }

        [Column("SubGroupId", Order = 2)]
        public int SubGroupId { set; get; }

        [MaxLength(150)]
        [Column("Name", Order = 3)]
        public string Name { set; get; }

        [Column("Price", Order = 4)]
        public decimal Price { set; get; }

        [MaxLength(200)]
        [Column("Description", Order = 5)]
        public string Description { set; get; }

        [MaxLength(150)]
        [Column("Qty", Order = 6)]
        public int Qty { set; get; }

        [MaxLength(100)]
        [Column("Materials", Order = 7)]
        public string Materials { set; get; }

        [MaxLength(100)]
        [Column("GemType", Order = 8)]
        public string GemType { set; get; }

        [MaxLength(50)]
        [Column("Weight", Order = 9)]
        public string Weight { set; get; }

        [MaxLength(150)]
        [Column("Dimensions", Order = 10)]
        public string Dimensions { set; get; }

        [Column("FreeService", Order = 11)]
        public string FreeService { set; get; }

        [Column("FeeService", Order = 12)]
        public string FeeService { set; get; }

        [Column("MoreDescription", Order = 13)]
        public string MoreDescription { set; get; }

        public int ImageId { set; get; }

        public string ImageName { set; get; }

        public string TempImageName { set; get; }

        public string GetTempImagePath(string type = null)
        {
            if (ImageName == null || ImageName == string.Empty)
            {
                return string.Empty;
            }
            string path = Constants.PATH_UPLOAD_IMAGE.Replace("..", "") + "/" + ImageName;
            string imagePath = System.Web.Hosting.HostingEnvironment.MapPath(path);
            type = type == null ? Constants.TYPE_IMAGE_MINIMUM : type;
            System.Drawing.Image image = Utils.GetResizedImage(imagePath, type);
            string tempImageUrl = Utils.GetImageUrl(image);
            return tempImageUrl;
        }
    }
}